use crate::sources::cgtn::videos::videos as cgtn_videos;
use crate::sources::chinadaily::videos::videos as chinadaily_videos;
use crate::utils::{Array, Video};
use tauri_plugin_store::StoreExt;

#[tauri::command]
pub fn get_videos(app_handle: tauri::AppHandle, source: &str, category: &str) -> Array<Video> {
    match (source, category) {
        ("history", "history") => {
            let store = app_handle.store(".history.dat").unwrap();
            let _ = store.reload();
            let json_value = store
                .get("history")
                .unwrap_or(serde_json::value::Value::Array(Vec::new()));
            let videos: Vec<Video> = serde_json::from_value::<Vec<Video>>(json_value).unwrap();
            return Array { items: videos };
        }
        ("cgtn", category) => cgtn_videos(category),
        ("chinadaily", category) => chinadaily_videos(category),
        _ => unimplemented!(),
    }
}
